package com.zengqingfa.designpattern.behavior.observer.spring;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 *
 * @fileName: Client
 * @author: zengqf3
 * @date: 2021-4-23 15:17
 * @description:
 */
public class Client {

    public static void main(String[] args) {
        /**
         * 观察者ConcreteObserver1收到消息:com.zengqingfa.designpattern.behavior.observer.spring.Notice[source=spring 观察者模式]
         * 观察者ConcreteObserver2收到消息:com.zengqingfa.designpattern.behavior.observer.spring.Notice[source=spring 观察者模式]
         */
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        //ApplicationContext：事件源，其中的 publishEvent()方法用于触发容器事件
        //主动触发
        context.publishEvent(new Notice("spring 观察者模式"));
    }
}
